#include "frmmanga.h"
#include "ui_frmmanga.h"
#include "resourcemanager.h"

frmManga::frmManga(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::frmManga)
{
    m_ui->setupUi(this);
}
frmManga::frmManga(ResourceManager * r,QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::frmManga)
{
    m_ui->setupUi(this);
    m_ui->tableWidget->setTable(r->getResources());
    m_r = r;
}

frmManga::~frmManga()
{
    delete m_ui;
}

void frmManga::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
void frmManga::setResourceList(ResourceManager * r)
{
    m_ui->tableWidget->setTable(r->getResources());
    m_r = r;
}

void frmManga::on_btnOk_clicked()
{
    this->close();
}

void frmManga::on_btnDelete_clicked()
{
    int row = m_ui->tableWidget->currentRow();
    QTableWidgetItem* item =  m_ui->tableWidget->item(row,0);
    int id = item->text().toInt(0,10);

    for(int i=0;i<m_r->getResources()->count();i++)
    {
	if(((Resource *)m_r->getResources()->at(i))->getId() == id)
	    m_r->getResources()->removeAt(i);
    }
    m_ui->tableWidget->setTable(m_r->getResources());
}
